package com.xlf.service.blog.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xlf.common.core.pojo.mode.AjaxResult;
import com.xlf.common.core.pojo.mode.BaseController;
import com.xlf.common.core.util.StringUtils;
import com.xlf.service.blog.domain.Type;
import com.xlf.service.blog.service.TypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/blog/admin/type")
public class AdminTypeController extends BaseController {

    @Resource
    TypeService typeService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('blog:admin:type:list')")
    public AjaxResult list(Type type){
        startPage();
        return success(getDataTable(typeService.getList(type)));
    }

    @PostMapping("/saveOrUpdate")
    @PreAuthorize("@ss.hasPermi('blog:admin:type:saveOrUpdate')")
    public AjaxResult saveOrUpdate(@RequestBody Type type){
        return success(typeService.saveOrUpdate(type));
    }

    @GetMapping("/query/{id}")
    @PreAuthorize("@ss.hasPermi('blog:admin:type:query')")
    public AjaxResult query(@PathVariable(value = "id") String id){
        return success(typeService.getById(id));
    }

    @DeleteMapping("/delete")
    @PreAuthorize("@ss.hasPermi('blog:admin:type:delete')")
    public AjaxResult delete(@RequestBody List<Long> ids){
        typeService.deleteTypeByIds(ids);
        return success("删除成功！");
    }

}
